package com.xiaoma.tpo.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.xiaoma.tpo.baseDao.BaseDaoImpl;
import com.xiaoma.tpo.domain.ImieLoginUser;
import com.xiaoma.tpo.domain.User;
import com.xiaoma.tpo.utils.Pager;
import com.xiaoma.verbal.baseDao.DefaultRowMapper;
@Repository
@SuppressWarnings("unchecked")
public class ImieLoginUserDAO extends BaseDaoImpl<ImieLoginUser>{

	
	public Object findByImie(String imie) {
		String sql = "select * from imie_login_user where imie = '"+imie+"'";
		
		List<Object> imieLoginUsers = this.jdbcTemplate.query(sql, new DefaultRowMapper(ImieLoginUser.class, this.getNameHandler()));
	
		return imieLoginUsers;
	}
	public Object findByDay(String imie) {
		String sql = "select * from imie_login_user where imie = '"+imie+"'";
		
		List<Object> imieLoginUsers = this.jdbcTemplate.query(sql, new DefaultRowMapper(ImieLoginUser.class, this.getNameHandler()));
		
		return imieLoginUsers;
	}
	public Pager findAllImiesByDay(String day, Integer page, Integer rows) {
		Pager pager = new Pager();
		String sql ;
		if(day != null && day != ""){
			sql = "select count(*) from imie_login_user where login_time >= '"+day+" 00:00:00' and login_time <= '"+day+" 23:59:59'";
		}else{
			sql = "select count(*) from imie_login_user";
			
		}
		int totalCount = jdbcTemplate.queryForInt(sql);
		pager.setTotalCount(totalCount);
		int startNum ;
		if(page == null || page == 0){
			startNum = 0;
		}else{
			startNum = (page-1)*rows;
		}
		String sqlList;
		if(day != null && day != ""){
			sqlList = "select * from imie_login_user where login_time >= '"+day+" 00:00:00' and login_time <= '"+day+" 23:59:59' order by login_time limit "+startNum+","+rows;
		}else{
			sqlList = "select * from imie_login_user order by login_time limit "+startNum+","+rows;
		}
		List<Object> imieUsers = jdbcTemplate.query(sqlList, new DefaultRowMapper(ImieLoginUser.class , this.getNameHandler()));
		pager.setList(imieUsers);
		return pager;
	}
	
	

	
}
